import pytest
import requests
from 接口自动化.case.DButils import *
from 接口自动化.send.Send import Send
from 接口自动化.utils.read_yaml import read_yaml
class TestUsersafe:

    @pytest.mark.parametrize( "args" ,  read_yaml("../data/usersafe.yaml")  )
    def test_usersafe(self,args):
        sql = "update user set password= %s where username  = %s"
        param = ["e10adc3949ba59abbe56e057f20f883e","lisi"]
        update(sql, param)

        name = args["username"]
        pwd= args["pwd"]
        session  = requests.session()

        se = Send()
        login = se.send_login(session,name,pwd)
        print(login["body"]["code"])

        id = args["id"]
        oldpwd= args["oldpwd"]
        newpwd = args["newpwd"]
        exp = args["exp"]
        result = se.send_usersafe(session,id,oldpwd,newpwd)

        assert result["code"] == 200 and result["body"]["code"] == exp

        sql = "update user set password= %s where username  = %s"
        param = ["e10adc3949ba59abbe56e057f20f883e","lisi"]
        update(sql, param)